import { FormGroup } from "@angular/forms";
import { format } from "date-fns";

export const formValidHelper = (formGroup: FormGroup): boolean => {
  // tslint:disable-next-line: forin
  for (const i in formGroup.controls) {
    formGroup.controls[i].markAsDirty();
    formGroup.controls[i].updateValueAndValidity();
  }

  return formGroup.valid;
};

export const dateFormat = (val: Date, formatStr?: string): string => {
  formatStr = formatStr || "yyyy-MM-dd HH:mm:ss";
  return val instanceof Date ? format(val, formatStr) : val;
};
